package com.tju.resource.oauth.controller.monitor;

import cn.hutool.json.JSONObject;
import com.tju.resource.business.ser.SerInfoService;
import com.tju.resource.result.Result;
import com.tju.resource.result.ResultEnum;
import com.tju.resource.result.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ServerInfoController {

    public static final String prefix = "/serinfo";

    @Autowired
    SerInfoService service;

    @PostMapping(prefix + "/allInfo")
    @PreAuthorize("hasAuthority('sys:monitoring:service:allinfo')")
    public Result<Object> allInfo() {
        JSONObject ret;
        Result<Object> resp;

        try {
            ret = service.all();
            resp = ResultUtil.success(ResultEnum.SUCCESS, "done.");
            resp.setData(ret);
        } catch (Exception e) {
            e.printStackTrace();
            resp = ResultUtil.error(ResultEnum.UNKONW_ERROR, e.getMessage());
        }

        return resp;
    }

}
